#include "StdAfx.h"


ContentManager::ContentManager(void)
{
}
ContentManager::~ContentManager(void)
{
}
void ContentManager::LoadContent()
{
	LoadBlock<Shader>	("Shaders", ShadersFolder);
	LoadBlock<Texture>	("Textures", TexturesFolder);
	LoadBlock<Mesh>		("Meshes", MeshesFolder);
	LoadBlock<Material>	("Materials", MaterialsFolder);
	LoadBlock<Model>	("Models", ModelsFolder);
	InitContent();
}
void ContentManager::Load(GameResource *resc)
{
	sptr<GameResource> p(resc);
	Resources.push_back(p);
	p->LoadFromFile();
}
void ContentManager::InitContent()
{
	for(unsigned int i=0;i<Resources.size();i++)
		Resources[i]->LoadFromFile();
	sptr<GameResource> shader_resc=_RESC("Basic_Shader"), texture_resc=_RESC("Sky_Texture");
	Shader* shader=_SHADER(shader_resc);
	shader->LoadTexture("DiffuseSampler", texture_resc);
}
sptr<GameResource> ContentManager::Get(string name)
{
	sptr<GameResource> p;
	try
	{
		p=Resources.GetByName(name);
	}
	catch(BException &e)
	{
		_log(e);
	}
	return p;
}

void ContentManager::AddToLog(string str)
{
	Log.push_back(str);
	SaveLog();
}
void ContentManager::SaveLog()
{
	std::ofstream stream(globals.ConfigFolderPath<<"log.txt", std::ios::trunc);
	for(unsigned int i=0;i<Log.size();i++)
		stream<<Log[i]<<"\n";
	stream.close();
}
